package ch10_thread.thread;

/**
 *
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class SixLifeCycle02 implements Runnable {
    public static void main(String[] args) {
        SixLifeCycle02 sixLifeCycle02 = new SixLifeCycle02();
        Thread t01 = new Thread(sixLifeCycle02);
        Thread t02 = new Thread(sixLifeCycle02);
        t01.start();
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t02.start();
        // TIMED_WAITING，计时等待
        System.out.println(t01.getState());
        // BLOCKED，阻塞状态
        System.out.println(t02.getState());
        try {
            Thread.sleep(1300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // WAITING，等待状态
        System.out.println(t01.getState());
    }

    @Override
    public void run() {
        syn();
    }

    public synchronized void syn() {
        try {
            Thread.sleep(100);
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
